//---------------------------------------------------------------------------

#ifndef TEncryptH
#define TEncryptH

#include <Classes.hpp>
#include <vector.h>
//#include <windows.h>
//#include <Ntdddisk.h>

//---------------------------------------------------------------------------
#define MAX_IDE_DRIVERS 4
#define IDENTIFY_BUFFER_SIZE 512

#define  m_cVxDFunctionIdesDInfo  1
#define  SENDIDLENGTH  sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE

#define  IDE_ATAPI_IDENTIFY  0xA1  //  Returns ID sector for ATAPI.
#define  IDE_ATA_IDENTIFY    0xEC  //  Returns ID sector for ATA.

//  GETVERSIONOUTPARAMS contains the data returned from the 
//  Get Driver Version function.
typedef struct _GETVERSIONOUTPARAMS
{
	BYTE bVersion;      // Binary driver version.
   BYTE bRevision;     // Binary driver revision.
   BYTE bReserved;     // Not used.
   BYTE bIDEDeviceMap; // Bit map of IDE devices.
   DWORD fCapabilities; // Bit mask of driver capabilities.
   DWORD dwReserved[4]; // For future use.
}GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS;

//  IDE registers
typedef struct __IDEREGS
{
	BYTE bFeaturesReg;       // Used for specifying SMART "commands".
	BYTE bSectorCountReg;    // IDE sector count register
	BYTE bSectorNumberReg;   // IDE sector number register
	BYTE bCylLowReg;         // IDE low order cylinder value
	BYTE bCylHighReg;        // IDE high order cylinder value
	BYTE bDriveHeadReg;      // IDE drive/head register
	BYTE bCommandReg;        // Actual IDE command.
	BYTE bReserved;          // reserved for future use.  Must be zero.
} MyIDEREGS, *MyPIDEREGS, *MyLPIDEREGS;

//  SENDCMDINPARAMS contains the input parameters for the
//  Send Command to Drive function.
typedef struct __SENDCMDINPARAMS
{
	DWORD     cBufferSize;   //  Buffer size in bytes
	MyIDEREGS    irDriveRegs;   //  Structure with drive register values.
	BYTE bDriveNumber;       //  Physical drive number to send
									 //  command to (0,1,2,3).
	BYTE bReserved[3];       //  Reserved for future expansion.
	DWORD     dwReserved[4]; //  For future use.
	BYTE      bBuffer[1];    //  Input buffer.
}MySENDCMDINPARAMS, *MyPSENDCMDINPARAMS, *MyLPSENDCMDINPARAMS;

//  IOCTL commands
#define  DFP_GET_VERSION          0x00074080
#define  DFP_SEND_DRIVE_COMMAND   0x0007c084
#define  DFP_RECEIVE_DRIVE_DATA   0x0007c088

#define  FILE_DEVICE_SCSI              0x0000001b
#define  IOCTL_SCSI_MINIPORT_IDENTIFY  ((FILE_DEVICE_SCSI << 16) + 0x0501)
#define  IOCTL_SCSI_MINIPORT 0x0004D008  //  see NTDDSCSI.H for definition
#define  VER_PLATFORM_WIN32s          0
#define  VER_PLATFORM_WIN32_WINDOWS   1
#define  VER_PLATFORM_WIN32_NT        2

// Status returned from driver
typedef struct __DRIVERSTATUS
{
	BYTE  bDriverError;  //  Error code from driver, or 0 if no error.
	BYTE  bIDEStatus;    //  Contents of IDE Error register.
								//  Only valid when bDriverError is SMART_IDE_ERROR.
	BYTE  bReserved[2];  //  Reserved for future expansion.
	DWORD  dwReserved[2];  //  Reserved for future expansion.
} DRIVERSTATUS1, *PDRIVERSTATUS1, *LPDRIVERSTATUS1;


// Structure returned by PhysicalDrive IOCTL for several commands
typedef struct __SENDCMDOUTPARAMS
{
	DWORD         cBufferSize;   //  Size of bBuffer in bytes
	DRIVERSTATUS1  DriverStatus;  //  Driver status structure.
	BYTE          bBuffer[1];    //  Buffer of arbitrary length in which to store the data read from the                                                       // drive.
} MySENDCMDOUTPARAMS, *MyPSENDCMDOUTPARAMS, *MyLPSENDCMDOUTPARAMS;


// (* Output Bbuffer for the VxD (rt_IdeDinfo record) *)
typedef struct _rt_IdeDInfo_
{
    BYTE IDEExists[4];
    BYTE DiskExists[8];
    WORD DisksRawInfo[8*256];
} rt_IdeDInfo, *pt_IdeDInfo;


// (* IdeDinfo "data fields" *)
typedef struct _rt_DiskInfo_
{
   BOOL DiskExists;
   BOOL ATAdevice;
   BOOL RemovableDevice;
   WORD TotLogCyl;
   WORD TotLogHeads;
   WORD TotLogSPT;
   char SerialNumber[20];
   char FirmwareRevision[8];
   char ModelNumber[40];
   WORD CurLogCyl;
   WORD CurLogHeads;
	WORD CurLogSPT;
} rt_DiskInfo;

class TEncryptHardDisk
{
public:
	AnsiString HardDiskNumber;
	AnsiString UserName;
	AnsiString ComputerBrand;
	AnsiString ComputerModel;
//	TEncryptHardDisk & operator = (const TEncryptHardDisk t);
private:
};

class TEncryptHardDiskList : public vector<TEncryptHardDisk>
{
public:
	AnsiString UserID;
	TEncryptHardDisk __fastcall New(const AnsiString HardDiskNumber,
											  const AnsiString UserName,
											  const AnsiString ComputerBrand,
											  const AnsiString ComputerModel);
	__fastcall TEncryptHardDiskList();
	AnsiString __fastcall GetHardDiskID(void);
	bool __fastcall Copyright(void);
private:
	char drivename[256];
	DWORD diskdata[256];
	bool __fastcall Find(const AnsiString HardID);
	char* __fastcall ConvertToString(DWORD diskdata [256], int firstIndex, int lastIndex);
	void __fastcall PrintInfo(int drive,DWORD diskdata[256]);
	int __fastcall DoIDENTIFY(HANDLE hPhysicalDriveIOCTL, MySENDCMDINPARAMS* pSCIP,
									  MySENDCMDOUTPARAMS* pSCOP, BYTE bIDCmd, BYTE bDriveNum,
									  PDWORD lpcbBytesReturned);
	void __fastcall ReadDriverInfo9X(void);
	AnsiString __fastcall ReadDriverInfoNT(void);
};

class TEncryptSoftwareDog
{
public:
	unsigned long DogNumber;
	AnsiString UserName;
	bool Actived;
};

class TEncryptSoftwareDogList : public vector<TEncryptSoftwareDog>
{
public:
	AnsiString UserID;
	__fastcall TEncryptSoftwareDogList();
	TEncryptSoftwareDog __fastcall New(const unsigned long DogNumber,
												  const AnsiString Name,
												  const bool Actived = false);
	bool __fastcall Copyright(void);
private:
	unsigned long __fastcall GetDogNumber(void);
};


enum eEncryptMode {NoEncrypt, HardDisk, HardDog, CUP};

class TEncrypt
{
public:
	eEncryptMode Mode;
	TEncryptHardDiskList HardDiskList;
	AnsiString UserID;

	__fastcall TEncrypt();
	bool __fastcall Agree(void);
private:
//	int __fastcall GetHardDiskNumber(void);
};


#endif
